package com.fishery.base.controller;

import com.fishery.base.service.PondFeedingService;
import com.fishery.base.service.SupplyService;
import com.fishery.base.service.TraceabilityService;
import com.fishery.entity.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/base/trace")
@Api(tags = "养殖养殖溯源信息接口")
@CrossOrigin
public class TraceabilityController {

	@Autowired
	private TraceabilityService traceabilityService;

	@Autowired
	private SupplyService supplyService;

	@Autowired
	private PondFeedingService pondFeedingService;

	@GetMapping("/{productId}/{size}/{current}")
	@ApiOperation("溯源水产品信息")
	public Result traceInformationOfProduct(@PathVariable(name = "productId", required = true)
											@ApiParam(value = "产品ID", required = true) String productId,
											@PathVariable(name = "size", required = true)
											@ApiParam(value = "尺寸", required = true) int size,
											@PathVariable(name = "current", required = true)
											@ApiParam(value = "页码", required = true) int current) {
		if (StringUtils.isEmpty(productId)) {
			return Result.error("溯源失败");
		}
		return Result.success().data(traceabilityService.traceInformation(productId, current, size));
	}

	@GetMapping("/feeding/{farmingId}/{size}/{current}/{catchTime}")
	@ApiOperation("溯源更多的喂养信息")
	public Result traceMoreFeedingInformationOfProduct(@PathVariable(name = "farmingId", required = true)
													   @ApiParam(value = "养殖编号", required = true) String farmingId,
													   @PathVariable(name = "size", required = true)
													   @ApiParam(value = "尺寸", required = true) int size,
													   @PathVariable(name = "current", required = true)
													   @ApiParam(value = "页码", required = true) int current,
													   @PathVariable(value = "catchTime", required = true)
													   @ApiParam(value = "捕捞时间", required = true) String catchTime) {
		if (StringUtils.isEmpty(farmingId)) {
			return Result.error("溯源失败");
		}
		return Result.success().data(pondFeedingService.traceFeedingByFarmingId(farmingId, current, size,catchTime));
	}

	@GetMapping("/{supplyId}")
	@ApiOperation("溯源投入品信息")
	public Result traceSupplyInformation(@PathVariable(name = "supplyId", required = true)
										 @ApiParam(value = "投入品id", required = true) String supplyId) {
		if (StringUtils.isEmpty(supplyId)) {
			return Result.error("溯源失败");
		}
		return Result.success().data(supplyService.traceSupplyInformation(supplyId));
	}
}
